package com.zHan.sky.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zHan.sky.common.result.Result;
import com.zHan.sky.dto.OrdersCancelDTO;
import com.zHan.sky.dto.OrdersConfirmDTO;
import com.zHan.sky.dto.OrdersRejectionDTO;
import com.zHan.sky.entity.Orders;
import com.zHan.sky.service.OrderDetailService;
import com.zHan.sky.service.OrdersService;
import com.zHan.sky.service.ShoppingCartService;
import com.zHan.sky.vo.OrderStatisticsVO;
import com.zHan.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单管理
 */
@RestController("adminOrderController")
@Slf4j
@RequestMapping("/admin/order")
@Api(tags = "订单相关接口")
public class OrderController {

    @Autowired
    private OrdersService ordersService;

    @Autowired
    private OrderDetailService orderDetailService;

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 订单搜索
     *
     * @param page
     * @param pageSize
     * @param number
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation(value = "订单搜索")
    public Result<Page<Orders>> page(int page, int pageSize, Long number, String beginTime,
                             String endTime,String phone,Integer status) {
        Page<Orders> pageInfo=ordersService.conditionSearch(page,pageSize,number,beginTime,
                endTime,phone,status);
        return Result.success(pageInfo);
    }

    /**
     * 取消订单
     *
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation(value = "取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        ordersService.cancelOrder(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 拒单
     *
     * @param ordersRejectionDTO
     * @return
     */
    @PutMapping("/rejection")
    @ApiOperation(value = "拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        ordersService.rejectionOrder(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    @ApiOperation(value = "查询订单详情")
    public Result<OrderVO> details(@PathVariable Long id) {
        OrderVO orderVO=ordersService.details(id);
        return Result.success(orderVO);
    }

    /**
     * 接单
     * @param ordersConfirmDTO
     * @return
     */
    @PutMapping("/confirm")
    @ApiOperation(value = "查询订单详情")
    public Result<Orders> confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        ordersService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 完成订单
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    @ApiOperation(value = "完成订单")
    public Result<Orders> complete(@PathVariable Long id) {
        ordersService.complete(id);
        return Result.success();
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation(value = "派送订单")
    public Result<Orders> delivery(@PathVariable Long id) {
        ordersService.delivery(id);
        return Result.success();
    }

    /**
     * 各个状态的订单数量统计
     * @return
     */
    @GetMapping("statistics")
    public Result<OrderStatisticsVO> statistics() {
        OrderStatisticsVO orderStatisticsVO=ordersService.statistics();
        return Result.success(orderStatisticsVO);
    }

}
